package com.gowow.gowoworionapp.ui.aty

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.gowow.gowoworionapp.R
import com.gowow.gowoworionapp.databinding.ActivityMainBinding
import com.gowow.gowoworionapp.ui.adapter.NavViewpageAdapter
import com.gowow.gowoworionapp.ui.fgt.DataRecordFragment
import com.gowow.gowoworionapp.ui.fgt.HomeFragment
import com.gowow.gowoworionapp.ui.fgt.MoYouCircleFragment

class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_main)
        binding = ActivityMainBinding.inflate(layoutInflater)

        //创建一个fragment集合
        val fragmentList = mutableListOf<Fragment>()
        fragmentList.add(HomeFragment())
        fragmentList.add(DataRecordFragment())
        fragmentList.add(MoYouCircleFragment())
        //给viewpage设置适配器
        binding.mainActivityVp.adapter =
            NavViewpageAdapter(supportFragmentManager, lifecycle, fragmentList)

       // //viewpage的点击事件
        //nav的点击事件
        binding.mainActivityNav.setOnNavigationItemSelectedListener {
            when (it.itemId) {
                R.id.menu_home -> {
                    title = resources.getString(R.string.main_activity_tab_home)
                    binding.mainActivityVp.currentItem = 0
                    return@setOnNavigationItemSelectedListener true
                }

                R.id.menu_data_record -> {
                    title = resources.getString(R.string.main_activity_tab_data_record)
                    binding.mainActivityVp.currentItem = 1
                    return@setOnNavigationItemSelectedListener true
                }

                R.id.menu_moyou_circle -> {
                    title = resources.getString(R.string.main_activity_tab_moyou_circle)
                    binding.mainActivityVp.currentItem = 2
                    return@setOnNavigationItemSelectedListener true
                }

            }
            false
        }

    }

}
